/*
 * @Author: szx
 * @Date: 2022-02-24 12:18:32
 * @LastEditTime: 2022-02-24 12:27:29
 * @Description:
 * @FilePath: \leetcode\1700-1799\1706\1706.js
 */
/**
 * @param {number[][]} grid
 * @return {number[]}
 */
var findBall = function (grid) {
    const n = grid[0].length;
    const res = new Array(n).fill(-1);
    for (let j = 0; j < n; j++) {
        let col = j;
        for (const row of grid) {
            const dir = row[col];
            col += dir;
            if (col < 0 || col == n || row[col] != dir) {
                col = -1;
                break;
            }
        }
        if (col >= 0) res[j] = col;
    }
    return res;
};
